
import { _decorator, Component, Node, Animation } from 'cc';
import { PopManager } from '../manager/PopManager';
import { AppControll, ConfigKey, EventName, PopView } from '../manager/AppControll';
import EvtManger from '../tools/EvtManger';
import { DataHelper } from '../system/DataHelper';
import { SoundManager } from '../manager/SoundManger';
import { GameData } from '../system/GameData';
const { ccclass, property } = _decorator;

@ccclass('gift')
export class Gift extends Component {
    @property(Node)
    mNdGift: Node = null;

    private mCurTime = 0;
    protected onLoad(): void {
        this.mNdGift.on(Node.EventType.TOUCH_END, this.OnBtnClick, this);
    }

    start() {
        // [3]
    }

    OnBtnClick() {
        AppControll.ShelvedTime = 0;
        EvtManger.do(EventName.showGift);
        PopManager.Instance<PopManager>().ShowPop(PopView.temporaryGift);
        SoundManager.Instance<SoundManager>().PlayEffect(GameData.btnClick);
    }

    update(deltaTime: number) {
        if (GameData.isPause) return;
        if (this.node.active) {
            this.mCurTime += deltaTime;
            if (this.mCurTime >= Number.parseInt(DataHelper.GetConfigByKey(ConfigKey.giftStopTime).value)) {
                this.mCurTime = 0;
                this.node.getComponent(Animation).stop()
                this.node.active = false;
                EvtManger.do(EventName.hideGift);
            }
        }
    }
}
